//2009/08/25 00:36:51
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class Containers
{
public:
    int wastedSpace(vector <int> containers, vector <int> packages)
    {
        int ret = 0;
		int i=0, j=0;
        for (; i<containers.size() && j<packages.size(); )
        {
            if (containers[i] >= packages[j])
            {
                containers[i] -= packages[j];
				j++;
            }
            else
            {
				ret += containers[i];
				i++;
            }
        }
		for(; i<containers.size(); i++) ret += containers[i];
		return ret;
    }
};
